package com.grantheath.erebus.controller.initializationCommands.initializeTransitionCommands
{
	import com.grantheath.erebus.model.enum.notifications.ErebusPreloaderNotifications;
	import com.grantheath.erebus.model.enum.notifications.ErebusPageNotifications;
	import com.grantheath.erebus.model.enum.notifications.ErebusPageLoaderNotifications;
	import com.grantheath.erebus.model.enum.notifications.ErebusTransitionNotifications;
	import com.grantheath.erebus.model.enum.names.ErebusProxyNames;
	import com.grantheath.erebus.model.interfaces.IErebusSiteTreeProxy;
	import com.grantheath.erebus.model.interfaces.IErebusPageNode;

	import org.puremvc.as3.patterns.command.SimpleCommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.ICommand;

	/**
	 * @author grantheath
	 */
	public class ErebusInitializeTransitionNormalFlowCommand extends SimpleCommand implements ICommand 
	{
		override public function execute(notification : INotification) : void
		{
			var siteTreeProxy : IErebusSiteTreeProxy = facade.retrieveProxy(ErebusProxyNames.SITE_TREE_PROXY) as IErebusSiteTreeProxy;
			var loadNode : IErebusPageNode = siteTreeProxy.loadQueue[0] as IErebusPageNode;
			var hideNode : IErebusPageNode = siteTreeProxy.hideQueue[0] as IErebusPageNode;
			
			if(loadNode) {
				sendNotification(ErebusPageLoaderNotifications.LOAD_PAGE, loadNode);
			}
			if(hideNode) {
				trace("hiding page: " + hideNode);
				sendNotification(ErebusPageNotifications.HIDE_PAGE, hideNode);
			} else {
				var uninitNode : IErebusPageNode = siteTreeProxy.uninitializeQueue[0] as IErebusPageNode;
				
				if(uninitNode){
					sendNotification(ErebusPageNotifications.UNINITIALIZE_PAGE, uninitNode);
				} else {
					var showNode : IErebusPageNode = siteTreeProxy.displayQueue[0] as IErebusPageNode;
					
					if(showNode) {
						sendNotification(ErebusPreloaderNotifications.SHOW_PRELOADER, showNode);
					} else {
						sendNotification(ErebusTransitionNotifications.TRANSITION_COMPLETE);
					}
				}
			}//end if(loadNode)
		}// end execute
		
		
	}//end class
}
